﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Camelio.BLL;

namespace Camelio
{
    public partial class SettingsForm : Form
    {
        public SettingsForm()
        {
            InitializeComponent();
        }

        private void SettingsForm_Load(object sender, EventArgs e)
        {
            textBox1.Text = Program.userName;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Admin ad = new Admin();
            ad.Where.AminUserName.Value = Program.userName;
            ad.Where.AminUserName.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Equal;
            ad.Query.Load();

            if (ad.AdminPassword == textBox2.Text)
            {
                if (textBox3.Text == textBox4.Text)
                {
                    ad.AdminPassword = textBox3.Text;
                    ad.Save();
                    textBox2.Text = "";
                    textBox3.Text = "";
                    textBox4.Text = "";
                    label4.ForeColor = Color.Black;
                    label2.ForeColor = Color.Black;
                    MessageBox.Show("تم تغيير كلمة المرور بنجاح", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("كلمة المرور الجديدة غير متابقة", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    label2.ForeColor = Color.Black;
                    label4.ForeColor = Color.Red;
                }
            }
            else
            {
                MessageBox.Show("كلمة المرور القديمة غير صحيحة", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                label2.ForeColor = Color.Red;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
        }
    }
}
